<template>
	<view class="page all">
		<view class="category-box">
			
			<view class="header">
				<template v-for="(item, i) in probList">
					<view class="item" >
						<view class="label">{{item.name}}</view>
						<view class="prob">概率 {{item.probability/100}}%</view>
					</view>
				</template>
				
			</view>
			
			<view v-if="goodsList.length>0" class="list">
				<template v-for="(goods, g) in goodsList">
					<view @click="viewDetail(goods)" class="item" :key="g">
						<image v-if="goods.tag_img" :src="goods.tag_img" class="icon tag"></image>
						
						<u-image :src="goods.product.image" width="320" height="320" border-radius="16" mode="widthFix"></u-image>
						<view class="info-box">
							<view class="name">{{goods.product.name}}</view>
							<view class="price">
								<text class="unit">¥ </text>
								<text class="money">{{goods.product.price}}</text>
								<text class="tips">参考价</text>
							</view>
						</view>
					</view>
				</template>
			</view>
			<view v-else class="empty-box">
				<u-empty mode="list"></u-empty>
			</view>
		</view>
		
		<!-- 商品详情 -->
		<u-popup v-model="showDetail" mode="bottom" border-radius="32">
			<view class="box-detail">
				<view class="header">商品详情</view>
				
				<view class="detail-wrap">
					<scroll-view class="detail-scroll-view" scroll-y="true">
						<view class="name">{{curProduct.name}}</view>
						
						<view class="price">
							<text class="unit">¥ </text>
							<text class="money">{{curProduct.price}}</text>
							<text class="tips">参考价</text>
						</view>
						
						<view class="intro">
							<u-parse :html="curProduct.detail" :tag-style="tagStyle"></u-parse>
						</view>
					</scroll-view>
				</view>
			</view>
		</u-popup>
		
		<!-- 提示信息 -->
		<u-toast ref="uToast" />

	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				queryParams: {
					blind_box_id: '',
					page: 1,
					limit: 10,
				},
				probList: [],
				goodsList: [],
				showDetail: false,
				curProduct: {},
				tagStyle: {
					p: 'color: #2E2B2B; font-size: 24rpx; line-height: 36rpx; margin-bottom: 20rpx;',
					span: 'font-size: 24rpx;',
					img: 'max-width: 702rpx; margin-top: 20rpx;'
				},
			}
		},
		onLoad(query) {
			const {blind_box_id} = query
			if(blind_box_id) this.queryParams.blind_box_id = blind_box_id
			
			this.getProb()
			this.getList()
		},
		onReachBottom() {
			this.getList()
		},
		methods: {
			viewDetail(item) {
				const {product_id} = item
				this.$net.req('/BlindBox/productDetail', {product_id}).then(res => {
					if (res.code === 200) {
						this.curProduct = res.data
						this.showDetail = true
					}
				})
				
			},
			getProb() {
				this.$net.req('/BlindBox/ProductProbability', {}).then(res => {
					if (res.code === 200) {
						this.probList = res.data
					}
				})
			},
			getList() {
				this.$net.req('/BlindBox/blindBoxProducts', this.queryParams).then(res => {
					if (res.code === 200) {
						if(this.queryParams.page===1) {
							this.goodsList = res.data.list
						} else if(res.data.list.length>0) {
							this.goodsList = this.goodsList.concat(res.data.list)
						}
						
						if(res.data.list.length>0) {
							++this.queryParams.page
						} else if(this.queryParams.page>1) {
							this.$refs.uToast.show({
								title: '没有更多数据了！',
								type: 'info'
							})
						}
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.page.all {
		padding: 24rpx;
		
		.category-box {
			width: 100%;
			
			.header {
				display: flex;
				flex-direction: row;
				align-items: center;
				width: 702rpx;
				height: 142rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				
				.item {
					flex: 1;
					text-align: center;
					
					
					.label {
						height: 36rpx;
						font-size: 28rpx;
						color: #666666;
						line-height: 36rpx;
					}
					
					.prob {
						height: 32rpx;
						font-size: 24rpx;
						color: #999999;
						line-height: 32rpx;
						margin-top: 10rpx;
					}
				}
			}
			
			.list {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				justify-content: space-between;
				width: 702rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				margin-top: 30rpx;
				padding: 20rpx;
				
			
				.item {
					width: 320rpx;
					height: 492rpx;
					margin-bottom: 24rpx;
					position: relative;
					
					.icon.tag {
						width: 92rpx;
						height: 48rpx;
						position: absolute;
						top: 16rpx;
						left: 16rpx;
						z-index: 10;
					}
							
					.info-box {
						padding: 20rpx;
						
						.name {
							height: 72rpx;
							font-size: 28rpx;
							color: #2E2B2B;
							line-height: 36rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							display: -webkit-box;
							-webkit-line-clamp: 2;
							-webkit-box-orient: vertical;
						}

						.price {
							height: 40rpx;
							font-size: 32rpx;
							font-weight: bold;
							color: #2E2B2B;
							line-height: 40rpx;
							margin-top: 20rpx;
							
							.unit {
								font-size: 24rpx;
								margin-right: 10rpx;
							}
							.tips {
								font-size: 24rpx;
								color: #C3C2C1;
								margin-left: 20rpx;
							}
						}
					}
				}
			}
			
			.empty-box {
				min-height: 60vh;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
		
		.box-detail {
			width: 750rpx;
			background: #FFFFFF;
			border-radius: 32rpx 32rpx 0 0;
			padding: 32rpx 24rpx;
			
			.header {
				height: 40rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #101010;
				line-height: 40rpx;
				text-align: center;
			}
			
			.detail-wrap {
				height: 834rpx;
				margin-top: 48rpx;
				
				.name {
					font-size: 32rpx;
					font-weight: bold;
					color: #101010;
					line-height: 48rpx;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}
				
				.price {
					height: 40rpx;
					font-size: 36rpx;
					color: #2E2B2B;
					line-height: 40rpx;
					margin-top: 20rpx;
					
					.unit {
						font-size: 24rpx;
						margin-right: 10rpx;
					}
					
					.money {
						font-weight: bold;
					}
					
					.tips {
						font-size: 24rpx;
						color: #999;
						line-height: 32rpx;
						margin-left: 20rpx;
					}
				}
				
				.intro {
					margin-top: 32rpx;
				}
			}
			
			
			
			
		}
			
		
	}
</style>
